package model;

import java.util.HashSet;
import java.util.Set;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;

import tools.Translator;

import com.google.inject.Inject;

public class Speaker {

	private String name;
	private Integer team;
	private Set<SpeakerRole> included;
	private boolean novice;
	private EventListenerList eventListenerList;

	@Inject
	public Speaker(Translator tr,
			Set<SpeakerRole> speakerRoles) {
		this.eventListenerList = new EventListenerList();
		this.setName(tr.tr("DEFAULT_NAME"));
		this.setTeam(null);
		this.setIncludedRoles(new HashSet<SpeakerRole>(speakerRoles));
	}

	public void addChangeListener(ChangeListener l) {
		eventListenerList.add(ChangeListener.class, l);
	}

	public void removeChangeListener(ChangeListener l) {
		eventListenerList.remove(ChangeListener.class, l);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getTeam() {
		return team;
	}

	public void setTeam(Integer team) {
		this.team = team;
	}

	public Set<SpeakerRole> getIncludedRoles() {
		return included;
	}

	public void setIncludedRoles(Set<SpeakerRole> included) {
		for (SpeakerRole r : included) {
			if (r == null) {
				throw new IllegalArgumentException(
						"All speakerRoles must not be null.");
			}
		}
		this.included = new HashSet<>(included);
		castChangeEvent();
	}

	private void castChangeEvent() {
		for (ChangeListener l : eventListenerList
				.getListeners(ChangeListener.class)) {
			l.stateChanged(new ChangeEvent(this));
		}
	}

	public boolean isNovice() {
		return novice;
	}

	public void setNovice(boolean novice) {
		this.novice = novice;
	}

}
